/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.user.HkUserSystemLabel;
import com.thinkgem.jeesite.modules.hk.sys.service.user.HkUserSystemLabelService;

/**
 * 用户标签Controller
 * @author 罗天文
 * @version 2018-08-29
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/user/hkUserSystemLabel")
public class HkUserSystemLabelController extends BaseController {

	@Autowired
	private HkUserSystemLabelService hkUserSystemLabelService;
	
	@ModelAttribute
	public HkUserSystemLabel get(@RequestParam(required=false) String id) {
		HkUserSystemLabel entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserSystemLabelService.get(id);
		}
		if (entity == null){
			entity = new HkUserSystemLabel();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:user:hkUserSystemLabel:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserSystemLabel hkUserSystemLabel, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserSystemLabel> page = hkUserSystemLabelService.findPage(new Page<HkUserSystemLabel>(request, response), hkUserSystemLabel); 
		model.addAttribute("page", page);
		return "hk/sys/user/hkUserSystemLabelList";
	}

	@RequiresPermissions("sys:user:hkUserSystemLabel:view")
	@RequestMapping(value = "form")
	public String form(HkUserSystemLabel hkUserSystemLabel, Model model) {
		model.addAttribute("hkUserSystemLabel", hkUserSystemLabel);
		return "hk/sys/user/hkUserSystemLabelForm";
	}

	@RequiresPermissions("sys:user:hkUserSystemLabel:edit")
	@RequestMapping(value = "save")
	public String save(HkUserSystemLabel hkUserSystemLabel, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserSystemLabel)){
			return form(hkUserSystemLabel, model);
		}
		hkUserSystemLabelService.save(hkUserSystemLabel);
		addMessage(redirectAttributes, "保存用户标签成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkUserSystemLabel/?repage";
	}
	
	@RequiresPermissions("sys:user:hkUserSystemLabel:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserSystemLabel hkUserSystemLabel, RedirectAttributes redirectAttributes) {
		hkUserSystemLabelService.delete(hkUserSystemLabel);
		addMessage(redirectAttributes, "删除用户标签成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkUserSystemLabel/?repage";
	}

}